﻿
Imports System.Runtime.InteropServices
Imports System.Xml
Imports SolidEdgeConstants
Imports SolidEdgeDraft
Imports SolidEdgeFramework
Imports SolidEdgeInstallData
Imports System.Drawing.Printing




Public Class Form1

    Public seType As System.Type
    Public seApp As Application = Nothing
    Public objSEEC As SolidEdgeFramework.SolidEdgeTCE = Nothing


    Public strMajorVersion As String
    Public strBulkLoaderPath As String
    Public blnV18Loaded As Boolean
    Public blnV19Loaded As Boolean
    Public blnV20Loaded As Boolean

    Public strTCConnectionFolder As String = ""
    Public strToplevelAssebly As String = ""
    Public strSE3DDoc As String = ""
    Public strCompaniondraftDoc(0) As String
    ' Public arrayOfFilesToBePackaged As ArrayList
    Public blnSEAlreadyRunning As Boolean = False
    Public FSO As Scripting.FileSystemObject = Nothing
    Public otext As Scripting.TextStream = Nothing
    Public objRootNode As TreeNode = Nothing
    Public strAppPath As String
    Public oiniFile As Scripting.TextStream = Nothing
    Public OOTBSEECRevRules As ArrayList
    'Public ListOfFilesActuallyCheckedOut As ArrayList
    Public strRevRuleToUse As String = ""
    Public blnDoesDraftExistInCurrentIR As Boolean = False
    Public objDraftPrintUtility As SolidEdgeDraft.DraftPrintUtility = Nothing



    Sub Garbage_Collect(ByVal obj As Object)


        Try

            '******* Added because of .NET
            If Not (obj Is Nothing) Then
                'Marshal.ReleaseComObject(obj)
                Marshal.FinalReleaseComObject(obj)
            End If

            GC.Collect(GC.MaxGeneration)
            GC.WaitForPendingFinalizers()
            GC.Collect(GC.MaxGeneration)
            GC.WaitForPendingFinalizers()
            '******* Added because of .NET
        Catch ex As Exception
            obj = Nothing
            GC.Collect(GC.MaxGeneration)
            GC.WaitForPendingFinalizers()
            GC.Collect(GC.MaxGeneration)
            GC.WaitForPendingFinalizers()

        End Try



    End Sub


    Public Sub RegMessageFilter()


        '******* Added because of .NET
        Try
            MyMessageFilter.MessageFilter.Register()
        Catch ex As Exception
            PrintLine("Error registering message filter.")
        End Try
        '******* Added because of .NET
    End Sub


    Public Sub UnRegMessageFilter()


        '******* Added because of .NET
        Try
            MyMessageFilter.MessageFilter.Revoke()
        Catch ex As Exception
            PrintLine("Error revoking the message filter.")
        End Try
        '******* Added because of .NET

    End Sub




    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        seType = Type.GetTypeFromProgID("SolidEdge.Application")


        ' Adds a ToolTip control (ToolTip1) to the form.
        ToolTip1.SetToolTip(Me.Button1, "Must generate a list of linked draft files before proceeding.")



        Dim jj As Integer = 0

        Dim strTmpString As String = ""
        'ReDim OOTBSEECRevRules(11)

        OOTBSEECRevRules = New ArrayList
        OOTBSEECRevRules.Add("Any Status; No Working")
        OOTBSEECRevRules.Add("Any Status; Working")
        OOTBSEECRevRules.Add("Latest Released")
        OOTBSEECRevRules.Add("Latest Working")
        OOTBSEECRevRules.Add("Latest by Alpha Rev Order")
        OOTBSEECRevRules.Add("Latest by Creation Date")
        OOTBSEECRevRules.Add("Precise Only")
        OOTBSEECRevRules.Add("Precise; Any Status")
        OOTBSEECRevRules.Add("Precise; Working")
        OOTBSEECRevRules.Add("Working(Curr Group);Any Status")
        OOTBSEECRevRules.Add("Working(Curr User);Any Status")
        OOTBSEECRevRules.Add("Working; Any Status")



        Try
            strAppPath = System.IO.Path.GetDirectoryName( _
                          System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
        Catch ex As Exception
            ' MsgBox(StrCanNotFindINIFile, MsgBoxStyle.OkOnly)
            Exit Sub
        End Try

        strAppPath = Microsoft.VisualBasic.Mid(strAppPath, 7, Microsoft.VisualBasic.Len(strAppPath))


        RegMessageFilter()

        If FSO Is Nothing Then
            FSO = New Scripting.FileSystemObject
        End If
        Me.CBRevisionRule.Items.Clear()

        If FSO.FileExists(strAppPath + "\Input.ini") = True Then
            oiniFile = FSO.OpenTextFile(strAppPath + "\Input.ini", Scripting.IOMode.ForReading, False, Scripting.Tristate.TristateUseDefault)
            Do While Not oiniFile.AtEndOfStream
                strTmpString = oiniFile.ReadLine
                If InStr(strTmpString, "LOGIN=", CompareMethod.Text) <> 0 Then
                    Me.TxtUserName.Text = Mid(strTmpString, 7, Len(strTmpString))
                End If
                If InStr(strTmpString, "PASSWORD=", CompareMethod.Text) <> 0 Then
                    Me.TxtPassword.Text = Mid(strTmpString, 10, Len(strTmpString))
                End If
                If InStr(strTmpString, "REVISION_RULE=", CompareMethod.Text) <> 0 Then
                    Dim strData As String = Mid(strTmpString, 15, Len(strTmpString))
                    Dim arrData As String() = strData.Split(",")
                    Me.CBRevisionRule.Text = Mid(arrData(0), 9, Len(arrData(0)))
                    For jj = 1 To arrData.Length - 1
                        Me.CBRevisionRule.Items.Add(arrData(jj))
                    Next
                End If
            Loop
            oiniFile.Close()
        Else
            For jj = 0 To OOTBSEECRevRules.Count - 1
                Me.CBRevisionRule.Items.Add(OOTBSEECRevRules(jj))
            Next

        End If



        Try
            Dim install As New SolidEdgeInstallData.SEInstallData
            strMajorVersion = install.GetMajorVersion

            strBulkLoaderPath = install.GetInstalledPath
            If CInt(install.GetMajorVersion) = 18 Then
                blnV18Loaded = True
            Else
                blnV18Loaded = False
            End If

            If CInt(install.GetMajorVersion) = 19 Then
                blnV19Loaded = True
            Else
                blnV19Loaded = False
            End If

            If CInt(install.GetMajorVersion) >= 20 Then
                blnV20Loaded = True
                Me.TxtURL.Enabled = True
                ' call sub to pull DB urls from TC
                GetDBUrlsFromXMLFile(strBulkLoaderPath + "\TeamcenterDBList.xml")
            Else
                blnV20Loaded = False
            End If
            Garbage_Collect(install)


        Catch ex As Exception
            MsgBox("Error creating Solid Edge info object.", MsgBoxStyle.Critical)
            Exit Sub
        End Try

        Try
            FSO = New Scripting.FileSystemObject

            Me.TextBox1.Text = FSO.GetSpecialFolder(Scripting.SpecialFolderConst.TemporaryFolder).Path
        Catch ex As Exception

        End Try




        Try
            Dim pkInstalledPrinters As String

            ' Find all printers installed
            For Each pkInstalledPrinters In _
                PrinterSettings.InstalledPrinters
                Me.cboInstalledPrinters.Items.Add(pkInstalledPrinters)
            Next pkInstalledPrinters

            ' Set the combo to the first printer in the list
            Me.cboInstalledPrinters.SelectedIndex = 0

        Catch ex As Exception

        End Try


        Me.Label10.Text = "Enter Item ID and Revision of the top level assembly."
        Me.Label10.Refresh()
    End Sub

    Public Function GetDBUrlsFromXMLFile(ByVal xmlFileName As String) As String

        Dim m_xmld As XmlDocument
        Dim m_ComponentsNode As XmlNode = Nothing
        Dim m_ListOfNOdes As XmlNodeList = Nothing
        Dim DBNodes As XmlNodeList = Nothing
        Dim nn As Integer
        Dim m_PropNode As XmlNode = Nothing
        Dim m_SequenceNode As XmlNode = Nothing
        Dim intCtr As Long
        Dim strNodeNAme As String
        Dim strDefaultDB As String = ""
        Dim jj As Integer

        intCtr = 0


        m_xmld = New XmlDocument()
        Try
            m_xmld.Load(xmlFileName)
        Catch ex As Exception
            GetDBUrlsFromXMLFile = ""
            Exit Function
        End Try
        Try
            m_ComponentsNode = m_xmld.SelectSingleNode("/TeamcenterDBList")
            m_ListOfNOdes = m_ComponentsNode.ChildNodes
            For nn = 0 To m_ListOfNOdes.Count - 1
                strNodeNAme = m_ListOfNOdes.Item(nn).Name.ToString
                If strNodeNAme = "DefaultDatabase" Then
                    strDefaultDB = m_ListOfNOdes.Item(nn).InnerText
                ElseIf strNodeNAme = "Databases" Then
                    m_SequenceNode = m_ListOfNOdes.Item(nn)
                    DBNodes = m_ListOfNOdes.Item(nn).SelectNodes("./Database")
                    For jj = 0 To DBNodes.Count - 1
                        m_PropNode = DBNodes.Item(jj)
                        Me.TxtURL.Items.Add(m_PropNode.FirstChild.InnerText)
                    Next

                End If
            Next
            Me.TxtURL.Text = strDefaultDB
        Catch ex As Exception
            GetDBUrlsFromXMLFile = ""
        End Try
        Garbage_Collect(m_PropNode)
        Garbage_Collect(DBNodes)
        Garbage_Collect(m_SequenceNode)
        Garbage_Collect(m_ListOfNOdes)
        Garbage_Collect(m_ComponentsNode)
        Garbage_Collect(m_xmld)

        GetDBUrlsFromXMLFile = ""



    End Function

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        With FolderBrowserDialog1
            .ShowDialog()
            Me.TextBox1.Text = .SelectedPath
        End With
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Dim blnToplevelnodeAlreadyCreated As Boolean = False
        Dim strTemporary As String = ""
        Dim pp As Integer = 0
        System.Windows.Forms.Cursor.Current = Cursors.WaitCursor

        strRevRuleToUse = Me.CBRevisionRule.Text

        If strRevRuleToUse = "" Then
            MsgBox("Please enter revision rule.")
            Exit Sub
        End If

        If Me.txtitemID.Text = "" Then
            MsgBox("Please enter item ID value.")
            Exit Sub
        End If

        If Me.Txtrevision.Text = "" Then
            MsgBox("Please enter item revision value.")
            Exit Sub
        End If

        Try
            If FSO.FileExists(strAppPath + "\Input.ini") = True Then
                FSO.DeleteFile(strAppPath + "\Input.ini", True)
            End If

            oiniFile = FSO.CreateTextFile(strAppPath + "\Input.ini", True)
            oiniFile.WriteLine("LOGIN=" + Me.TxtUserName.Text)
            oiniFile.WriteLine("PASSWORD=" + Me.TxtPassword.Text)

            strTemporary = "REVISION_RULE=DEFAULT:" + Me.CBRevisionRule.Text + ","
            For pp = 0 To Me.CBRevisionRule.Items.Count - 1
                strTemporary = strTemporary + Me.CBRevisionRule.Items(pp) + ","
            Next

            If OOTBSEECRevRules.Contains(Me.CBRevisionRule.Text) = False Then
                strTemporary = strTemporary + Me.CBRevisionRule.Text
            Else
                strTemporary = Mid(strTemporary, 1, Len(strTemporary) - 1)
            End If

            oiniFile.WriteLine(strTemporary)
            oiniFile.Close()
            strTemporary = ""
        Catch ex As Exception
            MsgBox("Error writing to ini file." + ex.Message)
        End Try

        Dim objChildNode As TreeNode = Nothing


        If (Me.tvBOM.GetNodeCount(False) = 1) Then
            ReleaseNode(Me.tvBOM.Nodes.Item(0))
            Me.tvBOM.Nodes.Clear()
        End If


        'Me.tvBOM.Visible = False

        Me.Label10.Text = "Connecting to Solid Edge ..... please wait."
        Me.Label10.Refresh()

        ConnectToSolidEdge()
        Try  'log into TC
            seApp.Visible = True
            If blnSEAlreadyRunning = False Then
                seApp.DisplayAlerts = False
            End If

            Me.Label10.Text = "Logging into Teamcenter ..... please wait."
            Me.Label10.Refresh()

            objSEEC = seApp.SolidEdgeTCE
            If Me.TxtPassword.Text = "" Then
                objSEEC.ValidateLogin(Me.TxtUserName.Text, "", "", "", Me.TxtURL.Text)
            Else
                objSEEC.ValidateLogin(Me.TxtUserName.Text, Me.TxtPassword.Text, "", "", Me.TxtURL.Text)
            End If


            objSEEC.SetTeamCenterMode(True)
            objSEEC.GetPDMCachePath(strTCConnectionFolder)

        Catch ex As Exception
            MsgBox("Erroring loging into Teamcenter with SEEC -> " + ex.Message)
            End
        End Try



        Dim NumberOfLinkedDocs1 As Long
        Dim ListOfItemRevIDs1 As Object = Nothing
        Dim ListOfFileSpecs1 As Object = Nothing
        Dim ListofFiles2 As Object = Nothing
        Dim NumberOfFiles2 As Integer
        Dim iii As Integer = 0
        Dim ctr1 As Integer = 0
        Dim NumberofDocToCheckout1 As Integer

        Dim ListofWhereUsedFiles As Object = Nothing

        Try
            Me.Label10.Text = "Determining list of files ..... please wait."
            Me.Label10.Refresh()
            objSEEC.GetListOfFilesFromTeamcenterServer(Me.txtitemID.Text, _
            Me.Txtrevision.Text.ToUpper, ListofFiles2, NumberOfFiles2)
        Catch ex As Exception
            MsgBox("error getting list of files under given item id:  " + Me.txtitemID.Text + "/" + Me.Txtrevision.Text + " ->" + ex.Message)
        End Try

        If NumberOfFiles2 = 0 Then
            MsgBox("Could not find the specified item in Teamcenter.  Please check your input.")
            Exit Sub
        End If

        For iii = 0 To NumberOfFiles2 - 1  ' get the list of SE docs in the given item revision in TC
            If InStr(UCase(ListofFiles2(iii)), ".ASM", CompareMethod.Text) <> 0 Then
                strToplevelAssebly = ListofFiles2(iii)
            End If
            'If InStr(UCase(ListofFiles2(iii)), ".PAR", CompareMethod.Text) <> 0 Then
            '    strToplevelAssebly = ListofFiles2(iii)
            'End If

        Next
        blnDoesDraftExistInCurrentIR = False

        For iii = 0 To NumberOfFiles2 - 1  ' get the list of SE docs in the given item revision in TC
            If InStr(UCase(ListofFiles2(iii)), ".ASM", CompareMethod.Text) <> 0 Then
                strToplevelAssebly = ListofFiles2(iii)
                If blnToplevelnodeAlreadyCreated = False Then
                    objRootNode = Me.tvBOM.Nodes.Add(Me.txtitemID.Text + "/" + Me.Txtrevision.Text + " -> " + strToplevelAssebly)
                End If
            End If
            If InStr(UCase(ListofFiles2(iii)), ".DFT", CompareMethod.Text) <> 0 Then
                If ctr1 > 0 Then
                    ReDim Preserve strCompaniondraftDoc(ctr1 + 1)
                End If
                strCompaniondraftDoc(ctr1) = ListofFiles2(iii)
                If objRootNode Is Nothing Then
                    If blnToplevelnodeAlreadyCreated = False Then
                        objRootNode = Me.tvBOM.Nodes.Add(Me.txtitemID.Text + "/" + Me.Txtrevision.Text + " -> " + strToplevelAssebly)
                        blnToplevelnodeAlreadyCreated = True
                    End If
                End If
                objChildNode = objRootNode.Nodes.Add(Me.txtitemID.Text + "/" + Me.Txtrevision.Text + " -> " + ListofFiles2(iii))
                objChildNode.Checked = True
                blnDoesDraftExistInCurrentIR = True
                ctr1 = ctr1 + 1
            End If

            If InStr(UCase(ListofFiles2(iii)), ".PAR", CompareMethod.Text) <> 0 Then
                strToplevelAssebly = ListofFiles2(iii)
                If blnToplevelnodeAlreadyCreated = False Then
                    objRootNode = Me.tvBOM.Nodes.Add(Me.txtitemID.Text + "/" + Me.Txtrevision.Text + " -> " + strToplevelAssebly)
                End If
            End If


            If InStr(UCase(ListofFiles2(iii)), ".PSM", CompareMethod.Text) <> 0 Then
                strToplevelAssebly = ListofFiles2(iii)
                If blnToplevelnodeAlreadyCreated = False Then
                    objRootNode = Me.tvBOM.Nodes.Add(Me.txtitemID.Text + "/" + Me.Txtrevision.Text + " -> " + strToplevelAssebly)
                End If
            End If
        Next


        Try
            If blnDoesDraftExistInCurrentIR = False Then   'we know a dft does not line in same Item Revision as the 3D component
                'do a where used to find if a linked dft file exists
                objSEEC.OnGetWhereUsedForAutomation(Me.txtitemID.Text, Me.Txtrevision.Text, strToplevelAssebly, ListofWhereUsedFiles)   'PR
                'got the draft file...now find the corresponding Item revision
                Dim strItemIDTest As String = ""
                Dim strInitialRevision As String = ""

                Dim blnfileExists As Boolean = False
                ' below there is code to find based off of revision....  there is currently no way to know what the revision naming
                ' rule is...  so we have to check for popular ones or at least cde up what the specific revision scheme is where the
                ' utility is going to be used.

                If ListofWhereUsedFiles.length > 0 Then
                    For iii = 0 To ListofWhereUsedFiles.length - 1
                        strItemIDTest = System.IO.Path.GetFileNameWithoutExtension(ListofWhereUsedFiles(iii))
                        Dim strExtension As String = System.IO.Path.GetExtension(ListofWhereUsedFiles(iii))
                        If strExtension.ToLower = ".dft" Then
                            objSEEC.DoesTeamCenterFileExists(strItemIDTest, "A", blnfileExists)
                            If blnfileExists = False Then
                                objSEEC.DoesTeamCenterFileExists(strItemIDTest, "01", blnfileExists)
                                If blnfileExists = False Then
                                    objSEEC.DoesTeamCenterFileExists(strItemIDTest, "-", blnfileExists)
                                    If blnfileExists = False Then
                                        objSEEC.DoesTeamCenterFileExists(strItemIDTest, "001", blnfileExists)
                                        If blnfileExists = False Then
                                            'can not find an initial item revision for the file returned above from the whereused API
                                        Else
                                            strInitialRevision = "001"
                                            GoTo foundIt
                                        End If
                                    Else
                                        strInitialRevision = "-"
                                        GoTo foundIt
                                    End If
                                Else
                                    strInitialRevision = "01"
                                    GoTo foundIt
                                End If
                            Else
                                strInitialRevision = "A"
                                GoTo foundIt
                            End If
foundIt:

                            Dim strRevisionTest As String = ""
                            blnfileExists = True
                            If strInitialRevision = "A" Then
                                Do While blnfileExists = True
                                    strInitialRevision = Chr(Asc(strInitialRevision) + 1)
                                    objSEEC.DoesTeamCenterFileExists(strItemIDTest, strInitialRevision, blnfileExists)
                                    If blnfileExists = False Then
                                        strRevisionTest = Chr(Asc(strInitialRevision) - 1)
                                    End If
                                Loop
                            End If

                            If strInitialRevision = "-" Then
                                'need to add code to deal with incrementing this revision naming scheme
                            End If

                            If strInitialRevision = "01" Then
                                'need to add code to deal with incrementing this revision naming scheme
                            End If

                            If strInitialRevision = "001" Then
                                'need to add code to deal with incrementing this revision naming scheme
                            End If

                            objChildNode = objRootNode.Nodes.Add(strItemIDTest + "/" + strRevisionTest + " -> " + ListofWhereUsedFiles(iii))
                            objChildNode.Checked = True
                        End If

                    Next
                End If

            End If
        Catch ex As Exception

        End Try


        ' added the specified top level assembly and it's companion draft now get the rest of linked files
        Try   'NumberOfLinkedDocs returns the instanced or total number of linked files NOT unique
            objSEEC.GetBomStructure(Me.txtitemID.Text, Me.Txtrevision.Text, Me.CBRevisionRule.Text, _
            True, NumberOfLinkedDocs1, ListOfItemRevIDs1, ListOfFileSpecs1)
        Catch ex As Exception
            'raise an error and do something

        End Try

        If NumberOfLinkedDocs1 = 0 Then
            Me.Label10.Text = "No linked documents found based on input revision rule."
            Me.Label10.Refresh()
            Exit Sub
        End If


        NumberofDocToCheckout1 = ListOfItemRevIDs1.getupperbound(0)

        For iii = 0 To NumberofDocToCheckout1
            If iii = 0 Then
                Me.Label10.Text = "Determining list of files ..... please wait."
                Me.Label10.Refresh()
            Else
                Me.Label10.Text = "Determining list of files ..... please wait."
                Me.Label10.Refresh()
            End If
            ExpandItemID(ListOfItemRevIDs1(iii, 0), ListOfItemRevIDs1(iii, 1))
            Me.tvBOM.ExpandAll()
        Next

        Me.tvBOM.ExpandAll()


        Me.Button1.Enabled = True

        Me.Label10.Text = "All entries checked will be processed.  Click OK to process."
       
        Me.Label10.Refresh()

        System.Windows.Forms.Cursor.Current = Cursors.Default
    End Sub


    'This recursive function drills down to the lowest children and
    ' call ReleaseComObject() back up the tree.  This helps ensure we
    ' release the objects in the order they were obtained.
    Private Sub ReleaseNode(ByVal node As TreeNode)

        For Each childNode As TreeNode In node.Nodes
            ReleaseNode(childNode)
        Next

        If Not (node.Tag Is Nothing) Then
            Try
                Marshal.ReleaseComObject(node.Tag)
                node.Tag = Nothing
            Catch
            End Try
        End If
    End Sub


    Public Sub ExpandItemID(ByVal strItemId As String, ByVal strIDrev As String)

        Dim ListofFiles As Object = Nothing
        Dim ListofWhereUsedFiles1 As Object = Nothing
        Dim NumberOfFiles As Integer
        Dim ii As Integer = 0
        Dim ctr As Integer = 0
        Dim strFilenametoCheckOut As String = ""
        Dim objChildNode1 As TreeNode = Nothing

        '****** at some point need to make sure this function will checkout multiple drafts!!!!!!!
        Try
            objRootNode = Nothing
            Garbage_Collect(objRootNode)
        Catch ex As Exception

        End Try


        Try
            objSEEC.GetListOfFilesFromTeamcenterServer(strItemId, strIDrev, ListofFiles, NumberOfFiles)
            If NumberOfFiles = 0 Then
                Exit Sub
            End If

            For ii = 0 To NumberOfFiles - 1  ' get the list of SE docs in the given item revision in TC
                If InStr(UCase(ListofFiles(ii)), ".PAR", CompareMethod.Text) <> 0 Or InStr(UCase(ListofFiles(ii)), ".PSM", CompareMethod.Text) <> 0 Or InStr(UCase(ListofFiles(ii)), ".ASM", CompareMethod.Text) <> 0 Or InStr(UCase(ListofFiles(ii)), ".PWD", CompareMethod.Text) <> 0 Then
                    strFilenametoCheckOut = ListofFiles(ii)
                    objRootNode = Me.tvBOM.Nodes.Add(strItemId + "/" + strIDrev + " -> " + ListofFiles(ii))
                    If InStr(UCase(ListofFiles(ii)), ".PAR", CompareMethod.Text) <> 0 Or InStr(UCase(ListofFiles(ii)), ".PSM", CompareMethod.Text) <> 0 Then
                        recursiveExpandItem(strItemId, strIDrev, objRootNode, strFilenametoCheckOut)
                    End If

                End If
            Next
            blnDoesDraftExistInCurrentIR = False
            For ii = 0 To NumberOfFiles - 1  ' get the list of SE docs in the given item revision in TC
                If InStr(UCase(ListofFiles(ii)), ".DFT", CompareMethod.Text) <> 0 Then
                    If ctr > 0 Then
                        ReDim Preserve strCompaniondraftDoc(ctr + 1)
                    End If
                    strCompaniondraftDoc(ctr) = ListofFiles(ii)
                    objChildNode1 = objRootNode.Nodes.Add(strItemId + "/" + strIDrev + " -> " + ListofFiles(ii))
                    objChildNode1.Checked = True
                    blnDoesDraftExistInCurrentIR = True
                    ctr = ctr + 1
                Else

                End If
            Next


            Try
                If blnDoesDraftExistInCurrentIR = False Then   'we know a dft does not line in same Item Revision as the 3D component
                    'do a where used to find if a linked dft file exists
                    objSEEC.OnGetWhereUsedForAutomation(strItemId, strIDrev, strFilenametoCheckOut, ListofWhereUsedFiles1)   'PR

                    'got the draft file...now find the corresponding Item revision
                    Dim strItemIDTest As String = ""
                    Dim strInitialRevision As String = ""

                    Dim blnfileExists As Boolean = False
                    If ListofWhereUsedFiles1.length > 0 Then
                        For iii = 0 To ListofWhereUsedFiles1.length - 1
                            strItemIDTest = System.IO.Path.GetFileNameWithoutExtension(ListofWhereUsedFiles1(iii))
                            Dim strExtension As String = System.IO.Path.GetExtension(ListofWhereUsedFiles1(iii))
                            If strExtension.ToLower = ".dft" Then
                                objSEEC.DoesTeamCenterFileExists(strItemIDTest, "A", blnfileExists)
                                If blnfileExists = False Then
                                    objSEEC.DoesTeamCenterFileExists(strItemIDTest, "01", blnfileExists)
                                    If blnfileExists = False Then
                                        objSEEC.DoesTeamCenterFileExists(strItemIDTest, "-", blnfileExists)
                                        If blnfileExists = False Then
                                            objSEEC.DoesTeamCenterFileExists(strItemIDTest, "001", blnfileExists)
                                            If blnfileExists = False Then
                                                'can not find an initial item revision for the file returned above from the whereused API
                                            Else
                                                strInitialRevision = "001"
                                                GoTo foundIt
                                            End If
                                        Else
                                            strInitialRevision = "-"
                                            GoTo foundIt
                                        End If
                                    Else
                                        strInitialRevision = "01"
                                        GoTo foundIt
                                    End If
                                Else
                                    strInitialRevision = "A"
                                    GoTo foundIt
                                End If
foundIt:

                                Dim strRevisionTest As String = ""
                                blnfileExists = True
                                If strInitialRevision = "A" Then
                                    Do While blnfileExists = True
                                        strInitialRevision = Chr(Asc(strInitialRevision) + 1)
                                        objSEEC.DoesTeamCenterFileExists(strItemIDTest, strInitialRevision, blnfileExists)
                                        If blnfileExists = False Then
                                            strRevisionTest = Chr(Asc(strInitialRevision) - 1)
                                        End If
                                    Loop
                                End If


                                If strInitialRevision = "-" Then

                                End If

                                If strInitialRevision = "01" Then

                                End If

                                objChildNode1 = objRootNode.Nodes.Add(strItemIDTest + "/" + strRevisionTest + " -> " + ListofWhereUsedFiles1(iii))
                                objChildNode1.Checked = True
                            End If

                        Next
                    End If



                End If


            Catch ex1 As Exception

            End Try
        Catch ex As Exception

        End Try





    End Sub


    Public Sub recursiveExpandItem(ByVal strItemId As String, ByVal strIDrev As String, ByVal oRootNode As TreeNode, ByVal strDatasetName As String)

        Dim ListofFilesRec As Object = Nothing
        Dim ListofWhereUsedFilesRec As Object = Nothing

        Dim jj As Integer = 0
        Dim ii As Integer = 0

        Dim strFilenametoCheckOutRec As String = ""
        Dim objChildNode1Rec As TreeNode = Nothing
        Dim objChildDraftNode1Rec As TreeNode = Nothing

        Try
            objSEEC.GetListOfIndirectFilesForGivenFile(strItemId, strIDrev, strDatasetName, strRevRuleToUse, "", ListofFilesRec)

            If ListofFilesRec.length > 0 Then
                objSEEC.CheckOutDocumentsFromTeamCenterServer(strItemId, strIDrev, True, , SolidEdgeFramework.DocumentDownloadLevel.SEECDownloadFirstLevel)
            End If

            For ii = 0 To ListofFilesRec.length - 1
                If ListofFilesRec(ii) <> strDatasetName Then
                    Dim strNewItemID As String = ""
                    Dim strNewItemRev As String = ""
                    objSEEC.GetDocumentUID(strTCConnectionFolder + "\" + ListofFilesRec(ii), strNewItemID, strNewItemRev) ' has to be in the cache first
                    objChildNode1Rec = Me.tvBOM.Nodes.Add(strNewItemID + "/" + strNewItemRev + " -> " + ListofFilesRec(ii))
                    'check for companion draft files for each of the linked files
                    Dim ListofFilesRec1 As Object = Nothing
                    Dim NumberOfFilesRec As Integer = 0
                    Dim ctr As Integer = 0
                    objSEEC.GetListOfFilesFromTeamcenterServer(strNewItemID, strNewItemRev, ListofFilesRec1, NumberOfFilesRec)
                    blnDoesDraftExistInCurrentIR = False
                    For jj = 0 To NumberOfFilesRec - 1  ' get the list of SE docs in the given item revision in TC
                        If InStr(UCase(ListofFilesRec1(jj)), ".DFT", CompareMethod.Text) <> 0 Then
                            If ctr > 0 Then
                                ReDim Preserve strCompaniondraftDoc(ctr + 1)
                            End If
                            strCompaniondraftDoc(ctr) = ListofFilesRec1(jj)
                            objChildDraftNode1Rec = objChildNode1Rec.Nodes.Add(strNewItemID + "/" + strNewItemRev + " -> " + ListofFilesRec1(jj))
                            objChildDraftNode1Rec.Checked = True
                            blnDoesDraftExistInCurrentIR = True
                            ctr = ctr + 1
                        Else

                        End If
                    Next

                    Try
                        If blnDoesDraftExistInCurrentIR = False Then   'we know a dft does not line in same Item Revision as the 3D component
                            'do a where used to find if a linked dft file exists
                            'objSEEC.OnGetWhereUsedForAutomation(strNewItemID, strNewItemRev, ListofFilesRec1(ii), ListofWhereUsedFilesRec)    'PR
                        End If
                    Catch ex1 As Exception
                        Dim junk As String = ""
                    End Try


                End If
            Next


        Catch ex As Exception

        End Try


    End Sub


    Sub ConnectToSolidEdge()


        Dim procCtr As Integer = 0
        Dim kk As Integer = 0



        Dim pList() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcesses
        For kk = 0 To pList.Count - 1
            If pList(kk).ProcessName.ToUpper = "EDGE" Then
                procCtr = procCtr + 1
            End If
        Next

        If procCtr > 2 Then
            MsgBox("Determined that there is more than 1 Edge.exe process running.")
            End
        End If

        If procCtr = 0 Then
            blnSEAlreadyRunning = False
        End If

        If procCtr = 1 Then
            blnSEAlreadyRunning = True
        End If

        Garbage_Collect(pList)
        Try
            If blnSEAlreadyRunning = True Then
                seApp = GetObject(, "SolidEdge.Application")
                If seApp Is Nothing Then
                    seApp = Marshal.GetActiveObject("SolidEdge.Application")
                    If seApp Is Nothing Then
                        MsgBox("Can not connect to an existing running instance of Solid Edge.")
                        end
                    End If
                End If

                seApp.SetGlobalParameter(SolidEdgeFramework.ApplicationGlobalConstants.seApplicationGlobalTeamCenterMode, True)
                seApp.DisplayAlerts = False
                blnSEAlreadyRunning = True
                Exit Sub
            End If

            If blnSEAlreadyRunning = False Then
                Me.Label10.Text = "Starting Solid Edge ....please wait."
                Me.Label10.Refresh()
                Try
                    seApp = Activator.CreateInstance(seType)
                    seApp.SetGlobalParameter(SolidEdgeFramework.ApplicationGlobalConstants.seApplicationGlobalTeamCenterMode, True)
                    seApp.DisplayAlerts = False
                    blnSEAlreadyRunning = True
                    Exit Sub
                Catch ex1 As Exception
                    Try
                        seApp = CreateObject("SolidEdge.Application")
                        seApp.SetGlobalParameter(SolidEdgeFramework.ApplicationGlobalConstants.seApplicationGlobalTeamCenterMode, True)
                        seApp.DisplayAlerts = False
                        blnSEAlreadyRunning = True
                        Exit Sub
                    Catch ex2 As Exception
                        MsgBox("Can not connect to Solid Edge" + ex1.Message)
                        End
                    End Try
                End Try
            End If


        Catch ex As Exception
            MsgBox("Can not connect to Solid Edge" + ex.Message)
            End
        End Try




        If seApp Is Nothing Then
            MsgBox("Can not connect to or start Solid Edge")
            End
        End If





    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim NumberofDocToCheckout As Long = 0
        Dim iii As Integer
        ''''''''''Dim ctr As Integer = 0
        Me.Label10.Text = " "
        Me.Label10.Refresh()

        Me.Label10.Text = "Connecting to Solid Edge ....please wait."
        Me.Label10.Refresh()
        ConnectToSolidEdge()
        Try  'log into TC
            seApp.Visible = True
            If blnSEAlreadyRunning = False Then
                seApp.DisplayAlerts = False
            End If

            Me.Label10.Text = "Logging into Teamcenter ....please wait."
            Me.Label10.Refresh()

            If Me.TxtPassword.Text = "" Then
                objSEEC.ValidateLogin(Me.TxtUserName.Text, "", "", "", Me.TxtURL.Text)
            Else
                objSEEC.ValidateLogin(Me.TxtUserName.Text, Me.TxtPassword.Text, "", "", Me.TxtURL.Text)
            End If
            seApp.DisplayAlerts = False
            objSEEC = seApp.SolidEdgeTCE
            objSEEC.SetTeamCenterMode(True)

        Catch ex As Exception
            MsgBox("Error logging into Teamcenter with SEEC -> " + ex.Message)
            End
        End Try

        System.Windows.Forms.Cursor.Current = Cursors.WaitCursor

        Try  ' add the info text file of the files exported.

            If (FSO Is Nothing) Then
                FSO = New Scripting.FileSystemObject
            Else
                otext = FSO.CreateTextFile(Me.TextBox1.Text + "\BatchProcessResults_" + _
                    Me.txtitemID.Text + "-" + Me.Txtrevision.Text + ".txt", True, False)
            End If

        Catch ex As Exception
            MsgBox("Error creating/writing to textfile: " + ex.Message)
        End Try

        otext.WriteLine("Machine used:" + My.Computer.Name)
        otext.WriteLine("User:" + Me.TxtUserName.Text)
        otext.WriteLine("Date:" + Now.ToShortDateString + " " + Now.ToShortTimeString)
        otext.WriteLine("Top Level Assembly Processed:" + Me.txtitemID.Text + "\" + Me.Txtrevision.Text)
        otext.WriteLine("Revision Rule used:" + Me.CBRevisionRule.Text)
        

        Try
            objSEEC.GetPDMCachePath(strTCConnectionFolder)
            otext.WriteLine("SEEC cache location:" + strTCConnectionFolder)
            otext.WriteLine("  ")
            otext.WriteLine("  ")
            If Me.RBPrint.Checked = True Then
                objDraftPrintUtility = seApp.GetDraftPrintUtility()
            End If


            Dim ctrNode As Integer
            Dim jj As Integer
            ctrNode = Me.tvBOM.Nodes.Count
            For jj = 0 To ctrNode - 1
                If jj = 0 Then
                    Me.Label10.Text = "processing linked Teamcenter item revision 1 of " + ctrNode.ToString + " ....please wait."
                    Me.Label10.Refresh()
                Else
                    Me.Label10.Text = "processing linked Teamcenter item revision " + (jj + 1).ToString + " of " + ctrNode.ToString + " ....please wait."
                    Me.Label10.Refresh()
                End If

                Dim objDraftDoc As SolidEdgeDraft.DraftDocument = Nothing

                ReadNodes(Me.tvBOM.Nodes.Item(jj))
                Garbage_Collect(objDraftDoc)
            Next

            If Me.RBPrint.Checked = True Then
                objDraftPrintUtility.AutoOrient = True
                objDraftPrintUtility.BestFit = True
                objDraftPrintUtility.Center = True
                objDraftPrintUtility.Orientation = SolidEdgeDraft.DraftPrintOrientationConstants.igDraftPrintLandscape
                objDraftPrintUtility.PrintAsBlack = True
                objDraftPrintUtility.Printer = Me.cboInstalledPrinters.Text
                objDraftPrintUtility.PrintOut()
                objDraftPrintUtility.RemoveAllDocuments()

                Garbage_Collect(objDraftPrintUtility)
            End If



        Catch ex As Exception

        End Try



        otext.Close()
        Garbage_Collect(otext)


        Me.Label10.Text = "Finished"
        Me.Label10.Refresh()


        seApp.Quit()


        Garbage_Collect(objSEEC)
        Garbage_Collect(seApp)
        Me.Button1.Enabled = False
        ' Me.Button5.Enabled = True

        UnRegMessageFilter()


        System.Windows.Forms.Cursor.Current = Cursors.Default
    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged

    End Sub


    Private Sub ReadNodes(ByVal node As TreeNode)

        Dim strItem_ID As String = ""
        Dim strID_rev As String = ""
        Dim strFilename_To_CheckOut As String = ""
        Dim nstart As Integer = 0
        Dim pstart As Integer = 0
        Dim FileToCheckin As System.Array
        Dim FileToDelete As System.Array

        objSEEC = seApp.SolidEdgeTCE

        nstart = InStr(node.Text, "/", CompareMethod.Text)
        If nstart <> 0 Then
            strItem_ID = Trim(Mid(node.Text, 1, nstart - 1))
            pstart = InStr(node.Text, ">", CompareMethod.Text)
            If pstart <> 0 Then
                strID_rev = Trim(Mid(node.Text, nstart + 1, pstart - 2 - nstart))
                strFilename_To_CheckOut = Trim(Mid(node.Text, pstart + 1, Len(node.Text)))
            End If
        End If

        If node.Checked = True Then
            Try
                If InStr(strFilename_To_CheckOut.ToUpper, ".DFT", CompareMethod.Text) <> 0 Then  'checked node is a draft file
                    If Me.RBPrint.Checked = True Then
                        Try
                            objSEEC.CheckOutDocumentsFromTeamCenterServer(strItem_ID, strID_rev, True, strFilename_To_CheckOut, SolidEdgeFramework.DocumentDownloadLevel.SEECDownloadFirstLevel)
                        Catch ex As Exception
                            'could not check out the file
                            otext.WriteLine("error downloading file " + strItem_ID + "\" + strID_rev + " error=" + ex.Message)
                            GoTo skip
                        End Try

                    End If

                    If Me.RBOpenSave.Checked = True Then   'open it update drawing views and save

                        'need to delete the draft file since I have seen issues checking out the file if a file of the same filename already exists
                        'in the SEEC cache
                        Try
                            If System.IO.File.Exists(strTCConnectionFolder + "\" + strFilename_To_CheckOut) = True Then
                                FileToDelete = Array.CreateInstance(GetType(Object), 1)
                                System.Array.Clear(FileToDelete, 0, 1)
                                FileToDelete(0) = strTCConnectionFolder + "\" + strFilename_To_CheckOut
                                objSEEC.DeleteFilesFromCache(FileToDelete)
                                System.Array.Clear(FileToDelete, 0, 1)
                            End If
                        Catch ex As Exception
                            otext.WriteLine("***Error deleting file from the SEEC cache " + _
                              strTCConnectionFolder + "\" + strFilename_To_CheckOut + " " + ex.Message)
                        End Try

                        Try
                            objSEEC.CheckOutDocumentsFromTeamCenterServer(strItem_ID, strID_rev, False, strFilename_To_CheckOut, SolidEdgeFramework.DocumentDownloadLevel.SEECDownloadAllLevel)
                        Catch ex As Exception
                            'could not check out the file
                            otext.WriteLine("error checking out file " + strItem_ID + "\" + strID_rev + " error=>" + ex.Message)
                            GoTo skip
                        End Try

                    End If



                    If Me.RBPrint.Checked = True Then   'open it and print it
                        PrintDoc(strFilename_To_CheckOut)
                    End If

                    If Me.RBOpenSave.Checked = True Then   'open it update drawing views and save
                        Dim objDraftDoc As SolidEdgeDraft.DraftDocument = Nothing
                        seApp.DoIdle()
                        objDraftDoc = seApp.Documents.Open(strTCConnectionFolder + "\" + strFilename_To_CheckOut)
                        objDraftDoc.UpdatePropertyTextCacheAndDisplay()
                        objDraftDoc.UpdatePropertyTextDisplay()
                        seApp.StartCommand(SolidEdgeConstants.DetailCommandConstants.DetailDrawingViewsUpdateViews)
                        objDraftDoc.Save()

                        'need to check the just saved document back into TC
                        Try
                            FileToCheckin = Array.CreateInstance(GetType(Object), 1)
                            System.Array.Clear(FileToCheckin, 0, 1)
                            FileToCheckin(0) = strTCConnectionFolder + "\" + strFilename_To_CheckOut
                            objSEEC.CheckInDocumentsToTeamCenterServer(FileToCheckin, False)
                            System.Array.Clear(FileToCheckin, 0, 1)
                        Catch ex As Exception
                            otext.WriteLine("***Error checking file back into Teamcenter " + _
                                strTCConnectionFolder + "\" + strFilename_To_CheckOut + " " + ex.Message)
                            'intSEECCount = CInt(Me.TxtMaxFiles.Text)
                            GoTo skip
                        End Try

                        objDraftDoc.Close()
                        Garbage_Collect(objDraftDoc)
                        otext.WriteLine("sucessfully updated and saved file  " + strItem_ID + "\" + strID_rev + "->" + strFilename_To_CheckOut)
                    End If


                End If
            Catch ex As Exception
                otext.WriteLine("error processing file " + strFilename_To_CheckOut + " error=" + ex.Message)
                GoTo skip
            End Try

        ElseIf node.Checked = False Then    'not checked so do nothing
          
        End If
skip:

        For Each childNode As TreeNode In node.Nodes
            nstart = InStr(childNode.Text, "/", CompareMethod.Text)
            If nstart <> 0 Then
                strItem_ID = Trim(Mid(childNode.Text, 1, nstart - 1))
                pstart = InStr(childNode.Text, ">", CompareMethod.Text)
                If pstart <> 0 Then
                    strID_rev = Trim(Mid(childNode.Text, nstart + 1, pstart - 2 - nstart))
                    strFilename_To_CheckOut = Trim(Mid(childNode.Text, pstart + 1, Len(childNode.Text)))
                End If
            End If

            If childNode.Checked = True Then
                Try
                    If InStr(strFilename_To_CheckOut.ToUpper, ".DFT", CompareMethod.Text) <> 0 Then  'checked node is a draft file

                        If Me.RBPrint.Checked = True Then
                            Try
                                objSEEC.CheckOutDocumentsFromTeamCenterServer(strItem_ID, strID_rev, True, strFilename_To_CheckOut, SolidEdgeFramework.DocumentDownloadLevel.SEECDownloadFirstLevel)
                                otext.WriteLine("Downloaded:" + strItem_ID + ":" + strID_rev + ":" + strFilename_To_CheckOut)
                            Catch ex As Exception
                                'could not check out the file
                                otext.WriteLine("error checking out file " + strItem_ID + "\" + strID_rev + " error=" + ex.Message)
                                GoTo skip1
                            End Try
                            
                        End If


                        If Me.RBOpenSave.Checked = True Then   'open it update drawing views and save

                            'need to delete the draft file since I have seen issues checking out the file if a file of the same filename already exists
                            'in the SEEC cache
                            Try
                                If System.IO.File.Exists(strTCConnectionFolder + "\" + strFilename_To_CheckOut) = True Then
                                    FileToDelete = Array.CreateInstance(GetType(Object), 1)
                                    System.Array.Clear(FileToDelete, 0, 1)
                                    FileToDelete(0) = strTCConnectionFolder + "\" + strFilename_To_CheckOut
                                    objSEEC.DeleteFilesFromCache(FileToDelete)
                                    System.Array.Clear(FileToDelete, 0, 1)
                                End If
                            Catch ex As Exception
                                otext.WriteLine("***Error deleting file from the SEEC cache " + _
                                  strTCConnectionFolder + "\" + strFilename_To_CheckOut + " " + ex.Message)
                            End Try


                            Try
                                objSEEC.CheckOutDocumentsFromTeamCenterServer(strItem_ID, strID_rev, False, strFilename_To_CheckOut, SolidEdgeFramework.DocumentDownloadLevel.SEECDownloadAllLevel)
                            Catch ex As Exception
                                'could not check out the file
                                otext.WriteLine("error checking out file " + strItem_ID + "\" + strID_rev + " error=" + ex.Message)
                                GoTo skip1
                            End Try
                        End If



                        If Me.RBPrint.Checked = True Then   'open it and print it
                            'open it and print it
                            PrintDoc(strFilename_To_CheckOut)
                        End If


                        If Me.RBOpenSave.Checked = True Then   'open it update drawing views and save
                            Dim objDraftDoc As SolidEdgeDraft.DraftDocument = Nothing
                            seApp.DoIdle()
                            objDraftDoc = seApp.Documents.Open(strTCConnectionFolder + "\" + strFilename_To_CheckOut)
                            objDraftDoc.UpdatePropertyTextCacheAndDisplay()
                            objDraftDoc.UpdatePropertyTextDisplay()
                            seApp.StartCommand(SolidEdgeConstants.DetailCommandConstants.DetailDrawingViewsUpdateViews)
                            objDraftDoc.Save()

                            'need to check the just saved document back into TC
                            Try
                                FileToCheckin = Array.CreateInstance(GetType(Object), 1)
                                System.Array.Clear(FileToCheckin, 0, 1)
                                FileToCheckin(0) = strTCConnectionFolder + "\" + strFilename_To_CheckOut
                                objSEEC.CheckInDocumentsToTeamCenterServer(FileToCheckin, False)

                            Catch ex As Exception
                                otext.WriteLine("***Error checking file back into Teamcenter " + _
                                    strTCConnectionFolder + "\" + strFilename_To_CheckOut + " " + ex.Message)
                                'intSEECCount = CInt(Me.TxtMaxFiles.Text)
                                GoTo skip1
                            End Try

                            objDraftDoc.Close()

                            Garbage_Collect(objDraftDoc)

                            otext.WriteLine("sucessfully updated and saved file  " + strItem_ID + "\" + strID_rev + "->" + strFilename_To_CheckOut)
                        End If

                    End If
                Catch ex As Exception
                    otext.WriteLine("error processing file " + strFilename_To_CheckOut + " error=" + ex.Message)
                End Try

            ElseIf childNode.Checked = False Then    'not checked so do nothing
               

            End If

skip1:

            If childNode.Nodes.Count > 0 Then
                ReadNodes(childNode)
            End If

        Next


    End Sub

    Public Function PrintDoc(ByVal strFname As String) As Boolean
        PrintDoc = False
        Dim objDraftDoc As SolidEdgeDraft.DraftDocument = Nothing
        Dim lPaperSize As Object = Nothing
        Dim lPaperOrient As Object = Nothing

        strFname = strTCConnectionFolder + "\" + strFname



        objDraftPrintUtility.AddFile(strFname)



        '******  below would be code to open each document and print it seperately
        'Try
        '    'open the draft document inactive fpor performance reasons....
        '    seApp.SetGlobalParameter(SolidEdgeFramework.ApplicationGlobalConstants.seApplicationGlobalSessionDraftOpenInactive, True)
        '    ' make read only
        '    seApp.SetGlobalParameter(SolidEdgeFramework.ApplicationGlobalConstants.seApplicationGlobalOpenAsReadOnlyDftFile, True)
        '    objDraftDoc = seApp.Documents.Open(strFname)

        '    ' Set a default, so response for unhandled cases is consistent
        '    lPaperSize = SolidEdgeConstants.PaperSizeConstants.igAnsiBWide
        '    lPaperOrient = SolidEdgeDraft.DraftPrintOrientationConstants.igDraftPrintLandscape

        '    objDraftDoc.PrintOut(Printer:=Me.cboInstalledPrinters.Text, ColorAsBlack:=True)
        '    If Not objDraftDoc Is Nothing Then
        '        objDraftDoc.Close()
        '        seApp.DoIdle()
        '    End If
        '    Garbage_Collect(objDraftDoc)
        '    PrintDoc = True
        '    Exit Function
        'Catch ex As Exception
        '    otext.WriteLine("error printing file " + strFname)
        '    PrintDoc = False
        '    Garbage_Collect(objDraftDoc)
        '    Exit Function
        'End Try

        

    End Function

    Private Sub Button1_DragLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.DragLeave

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        End
    End Sub

    Private Sub RBPrint_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RBPrint.CheckedChanged
        If RBPrint.Checked = True Then
            Me.GroupBox1.Enabled = True
        End If

        If RBPrint.Checked = False Then
            Me.GroupBox1.Enabled = False
        End If
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim strPathToNotpad As String
        Try

            If FSO Is Nothing Then
                FSO = New Scripting.FileSystemObject
            End If
            strPathToNotpad = FSO.GetSpecialFolder(Scripting.SpecialFolderConst.WindowsFolder).Path + "\notepad.exe"

            Call Shell(strPathToNotpad + " " + Me.TextBox1.Text + "\BatchProcessResults_" + _
                    Me.txtitemID.Text + "-" + Me.Txtrevision.Text + ".txt", AppWinStyle.NormalFocus)
        Catch ex As Exception
            MsgBox("Error displaying file", MsgBoxStyle.OkOnly)
        End Try
    End Sub
End Class
